package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.dto.R;
import com.qf.pojo.Book;
import com.qf.service.BookService;
import com.qf.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("/book")
    public R findAllAreas(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "1") int limit, String bookname, @RequestParam(defaultValue = "0") int datastatus){
        PageInfo<Book> allBooks = bookService.findAllBooks(page, limit, bookname, datastatus);
        return  R.setOk(allBooks);
    }

    @PostMapping("/newbook")
    public R addbook(@RequestBody Book book){
        bookService.insertbook(book);
        return R.setOk(book);
    }
}
